<?php

namespace app\index\controller;

class Banner extends Common
{
    /**
     * 查询轮播图
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function query()
    {
        $db = db("banner");
        $type = input('type');
        if ($type) {
            $db->where('type', $type);
        }
        $db->where('status', 0);
        $db->where(
            function ($query) {
                $query->where('starttime', '>= time', date("Y-m-d", time()));
                $query->whereOr('starttime', null);
            });
        $db->where(function ($query) {
            $query->where('endtime', '<= time', date("Y-m-d", time()));
            $query->whereOr('endtime', null);
        });
        $data = $db->field("title,image,url")->order('sort')->select();
        $this->rest($data);
    }

}
